import { Notification, MessageBox, Message } from 'element-ui'
const js = {
	showMessage: function(message, title, type, timeout) {
		Message({
		  message: message,
		  type: 'success',
		  duration: 5 * 1000
		})
	},
	ajaxSubmit: function(url, data, callback, dataType, async, message) {
		js.loading(message == undefined ? js.text("loading.submitMessage") : message);
		if (typeof data == "function") {
			message = async;
			async = dataType;
			dataType = callback;
			callback = data;
			data = undefined
		}
		var options = {};
		if (typeof callback == "object") {
			options = callback;
			callback = options.callback;
			dataType = options.dataType;
			async = options.async;
			message = options.message
		}
		$.ajax($.extend(true, {
			type: "POST",
			url: url,
			data: data,
			dataType: dataType == undefined ? "json" : dataType,
			async: async == undefined ? true : async,
			error: function(data) {
				js.showErrorMessage(data.responseText);
				js.closeLoading(0, true)
			},
			success: function(data, status, xhr) {
				js.closeLoading();
				if (typeof callback == "function") {
					callback(data, status, xhr)
				} else {
					js.log(data)
				}
			}
		}, options))
	},
	showErrorMessage: function(responseText) {
		console.log(responseText);
	},
	loading: function(message, ignoreMessageIfExists) {
	},
	closeLoading: function(timeout, forceClose) {
	},
	text: function(code, params) {
	},
	remove:function(arr,val) { 
		var index = arr.indexOf(val); 
		if (index > -1) { 
		arr.splice(index, 1); 
		}
	},
};
export default js
